#coding=utf-8
import block
import util
import math

class World:
    citys = []
    fields = []
    secretAreas = []
    mapBlocks = []
    w = 1
    h = 1
    lv = 1
    def randWorld(self):
        '随机世界'
        s = self.w * self.h
        for i in range(0,s):
            x,y = util.getMapXY(i, self.w, self.h)
            b = block.Block(x, y)
            b.lv = self.lv
            self.mapBlocks.append(b)
    def worldLvUp(self):
        '世界升级,增长一圈'
        self.lv += 1
        w = self.w + 2
        h = self.h + 2
        tmpBlocks = []
        s = w * h
        for i in range(0,s):
            x,y = util.getMapXY(i, w, h)
            b = block.Block(x, y)
            b.lv = self.lv
            tmpBlocks.append(b)
        for ih in range(0, self.h):
            idx = util.getMapIndex(-int(w/2)+1,int(h/2)-1-ih,w,h)
            for n in range(0,self.w):
                tmpBlocks[idx+n] = self.mapBlocks[ih*self.w+n]
        self.mapBlocks = tmpBlocks
        self.w = w
        self.h = h
    def getBlock(self, x, y):
        idx = util.getMapIndex(x,y,self.w,self.h)
        return self.mapBlocks[idx]
    def dump(self):
        out = ''
        s = self.w * self.h
        for i in range(0,s):
            out += str(self.mapBlocks[i].lv)
            if (i+1) % self.w == 0:
                out += '\n'
        return out

'''
world = World()
print '-----'
world.randWorld()
print world.dump()
print '-----'
world.worldLvUp()
print world.dump()
print '-----'
world.worldLvUp()
print world.dump()
print '-----'
world.worldLvUp()
print world.dump()
print '-----'
world.worldLvUp()
print world.dump()
'''